
import cv2
from PyQt5.QtCore import QStringListModel, pyqtSignal
from PyQt5.QtWidgets import QMainWindow, QMessageBox
from ui import Ui_MainWindow
from threading import Event
from PyQt5 import QtCore, QtGui, QtWidgets
class Windows(QMainWindow, Ui_MainWindow):
    received = pyqtSignal(str)

    def __init__(self, app, parent=None):
        super(Windows, self).__init__(parent)
        self.app = app
        self.setupUi(self)
        self.btn_start.clicked.connect(self.switch)
        self.eventRunning = Event()


    def flash_img(self, image, ratio):
        size = (int(self.label_img.width()), int(self.label_img.width() * ratio))
        shrink = cv2.resize(image, size, interpolation=cv2.INTER_AREA)
        # cv2.imshow('img', shrink)
        shrink = cv2.cvtColor(shrink, cv2.COLOR_BGR2RGB)


        self.QtImg = QtGui.QImage(shrink.data, shrink.shape[1],
                                  shrink.shape[0], shrink.shape[1] * 3,
                                  QtGui.QImage.Format_RGB888)
        self.label_img.setPixmap(QtGui.QPixmap.fromImage(self.QtImg))

    def switch(self):
        if self.eventRunning.isSet():
            self.label_img.setText("手势识别会\n议控制系统")
            self.btn_start.setText("开启识别")
            self.eventRunning.clear()
        else:
            self.eventRunning.set()
            self.btn_start.setText("停止识别")

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())